package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.CourseDto;
import com.qk.entity.Course;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/courses")
@RestController
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping
    public Result list(CourseDto courseDto) {
        PageResult<Course> list = courseService.list(courseDto);
        return Result.success(list);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        courseService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Course course) {
        courseService.add(course);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Course course = courseService.getById(id);
        return Result.success(course);
    }
    @PutMapping
    public Result upDate(@RequestBody Course course) {
        courseService.upDate(course);
        return Result.success();
    }
    @GetMapping("list")
    public Result listAll() {
        List<Course> list = courseService.listAll();
        return Result.success(list);
    }
    @GetMapping("/subject/{subject}")
    public Result listBySubject(@PathVariable Integer subject) {
        List<Course> list = courseService.listBySubject(subject);
        return Result.success(list);
    }

}
